/*
 * main.c
 *
 *  Created on: Dec 28, 2011
 *      Author: sitnoam
 */
#include <stdio.h>
#include <malloc.h>
#include "list.h"
typedef struct uthread_s {
	list_t queue; /* NOAM: This line must be first and not a pointer. If you'll change it, i'll shoot you. */
	list_t join_by; /* NOAM: This line must be second. */
	int prio;
	int state;
	int flag_alive;
	int ret_value;
	void* stack;

//	uthread_id join_to;
} *uthread;
int main() {


	uthread thread1 = malloc(sizeof(*thread1));
	uthread thread2 = malloc(sizeof(*thread2));
	uthread thread3 = malloc(sizeof(*thread3));
	uthread thread4 = malloc(sizeof(*thread3));
	uthread thread5 = malloc(sizeof(*thread3));
	thread1->prio = 11;
	thread2->prio = 22;
	thread3->prio = 33;
	thread4->prio = 44;
	thread5->prio = 55;
	list_t thelist;
	INIT_LIST_HEAD(&(thelist));


	list_add_tail(&(thread1->queue),&thelist);
//	list_add_tail(&(thread2->queue),&thelist);
//	list_add_tail(&(thread3->queue),&thelist);
//	list_add_tail(&(thread4->queue),&thelist);
//	list_add_tail(&(thread5->queue),&thelist);

	list_t *iter,*temp;
	printf("ff %d\n",((uthread)(thelist.next->prev->prev))->prio);
	list_for_each_safe(iter,temp,&thelist) {
		printf("aa %d\n", ((uthread)iter)->prio);
//		if (((uthread)iter)->prio == 22) {
//			list_del(iter);
//			free((uthread)iter);
//		}
	}
	list_for_each_safe(iter,temp,&thelist) {
			printf("aa %d\n", ((uthread)iter)->prio);
		}
	printf("end\n");
//	uthread_init();
//	printf("Hello World!\n");
//	int x = 1;
//	while(1) {
//		x++;
//		if (x % 100000 == 0)
//			printf("%d\n",x++);
//	};
	free(thread1);
//	free(thread2);
	free(thread3);
	free(thread4);
	free(thread5);
	return 0;
}

